﻿using LeanApp.Bll;
using System.Windows.Controls;
using System.Windows.Data;

namespace LeanApp.View
{
    /// <summary>
    /// GroupInfoCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class GroupInfoCtrl : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="model">数据实体</param>
        public GroupInfoCtrl(string title, SpcBll model)
        {
            InitializeComponent();
            _title = title;
            _model = model;
            InitialDataGrid();
            InitialData();
        }

        /// <summary>
        /// 初始化表格
        /// </summary>
        private void InitialDataGrid()
        {
            DataGridTextColumn column1 = new DataGridTextColumn { Header = "组号", Binding = new Binding("Index"), Width = DataGridLength.SizeToHeader };
            DataGridTextColumn column2 = new DataGridTextColumn { Header = "组内边界", Binding = new Binding("GroupTag"), Width = DataGridLength.SizeToHeader };
            dataGrid.Columns.Add(column1); // 添加新列到DataGrid中，但不推荐这种方式，通常建议预先定义好列或者在XAML中定义。
            dataGrid.Columns.Add(column2); // 添加新列到DataGrid中，但不推荐这种方式，通常建议预先定义好列或者在XAML中定义。
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitialData()
        {
            title.Text = _title;
            if (_model != null && _model.GroupDatas != null && _model.GroupDatas.Count > 0)
            {
                _model.GroupDatas.ForEach(a =>
                {
                    dataGrid.Items.Add(a);
                });
            }

        }

        /// <summary>
        /// 数据实体列表
        /// </summary>
        private SpcBll _model = new SpcBll();
        /// <summary>
        /// 标题
        /// </summary>
        private string _title = "";
    }
}
